package com.hualan.sfzy.controller.mind;
import com.hualan.sfzy.entity.mind.TestProblem;
import com.hualan.sfzy.service.mind.TestProblemService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.awt.*;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("testProblem")
public class TestProblemController {
    @Autowired
    private TestProblemService testProblemService;

    @PostMapping
    public int insert(@RequestBody TestProblem testProblem) {
        testProblemService.insertWithOptions(testProblem);
        testProblemService.add(testProblem);
        return Result.success().getCode();
    }
    @PutMapping
    public int update(@RequestBody TestProblem testProblem) {
        return testProblemService.edit(testProblem);
    }

    @DeleteMapping("/{id}")
    public int delete(@RequestParam Integer id) {
        return testProblemService.remove(id);
    }

    @DeleteMapping()
    public int deleteBatch(@RequestParam Integer[] ids) {
        return testProblemService.removeBatch(ids);
    }

    @GetMapping
    public List<TestProblem> select(@RequestBody TestProblem testProblem) {
        return testProblemService.find();
    }

    @GetMapping("/{id}")
    public TestProblem selectById(@PathVariable Integer id) {
        return testProblemService.findById(id);
    }

    @GetMapping("/page")
    public Map<String, Object> findByPage(@RequestParam(value="pageNum",required = false, defaultValue = "1") Integer pageNum,
                                          @RequestParam(value="pageSize",required = false,defaultValue = "10") Integer pageSize,
                                         TestProblem testProblem) {
        return testProblemService.findByPage(pageNum, pageSize, testProblem);
    }
}